/* reworp02.p - REPETITIVE                                                    */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: reworp02.p 2366 2010-11-10 01:47:19Z zzh                          $: */
/*F0PN*/ /*V8:ConvertMode=FullGUIReport                                       */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 8.6      LAST MODIFIED: 10/14/97   BY: mzv *K0YF*                */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb                */
/* REVISION: 9.1      LAST MODIFIED: 09/11/00   BY: *N0RQ* Mudit Mehta        */
/* Revision: 1.5.1.6.3.1  BY: Paul Donnelly (SB) DATE: 06/28/03 ECO: *Q00K* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*-Revision end---------------------------------------------------------------*/

/* CUM WORKORDER COST REPORT                                                  */

{us/mf/mfdtitle.i "99 "}


{us/px/pxmaint.i}
{us/px/pxphdef.i wowrxr}
{us/wo/woconsdf.i}
{us/wr/wrttiro.i reference-only}

define  variable altpart          like ptal_alt_part no-undo.
define  variable altpart1         like ptal_alt_part no-undo.
define variable line like wo_line.
define variable line1 like wo_line label "To".
define variable lot like wo_lot.
define variable lot1 like wo_lot label "To".
define variable part like wo_part.
define variable part1 like wo_part label "To".
define variable site like wo_site.
define variable site1 like wo_site label "To".
define variable endeff as date label "End Effective".
define variable endeff1 as date label "To".
define variable report_bom like mfc_logical label "Report BOM"
   initial yes.
define variable ext_amt like iro_cost_tot column-label "Extended".
define variable order_type_key  like lngd_key1 initial "0".
define variable c-lngd-dataset like lngd_det.lngd_dataset initial "wo_mstr" no-undo.
define variable orderType as character format "x(9)" label "Include Repetitive/Discrete/Both" no-undo.

form
   lot                  colon 20
   lot1                 colon 45
   part                 colon 20
   part1                colon 45
   site                 colon 20
   site1                colon 45
   line                 colon 20
   line1                colon 45
   endeff               colon 20
   endeff1              colon 45
   altpart              colon 20
   altpart1             colon 45 label "To"
   skip(1)
   report_bom           colon 45
   orderType            colon 45
with frame a side-labels width 80.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* CLEAR  TEMP TABLE OF OPERATION COSTS */
{us/px/pxrun.i &PROC       = 'initialize_tt_iro_det'
   &PROGRAM    = 'wowrxr.p'
   &HANDLE     = ph_wowrxr
   &NOAPPERROR = true
   }

find first gl_ctrl  where gl_ctrl.gl_domain = global_domain no-lock.

for first lngd_det where lngd_dataset = c-lngd-dataset
   and lngd_field   = "orderType"
   and lngd_lang    = global_user_lang
   and lngd_key1    = order_type_key
no-lock:
end.

if available lngd_det then orderType = lngd_key2.
else orderType = "".

{us/wb/wbrp01.i}

repeat:

   if lot1 = hi_char then lot1 = "".
   if part1 = hi_char then part1 = "".
   if site1 = hi_char then site1 = "".
   if line1 = hi_char then line1 = "".
   if altpart1   = hi_char  then altpart1  = "".

   if c-application-mode <> 'web' then
   update
      lot lot1
      part part1
      site site1
      line line1
      endeff endeff1
      altpart
      altpart1
      report_bom
      orderType
   with frame a

      editing:
      if frame-field = "orderType" then do:
         {us/mf/mfnp05.i lngd_det lngd_det
            "lngd_dataset    = c-lngd-dataset
              and lngd_field  = 'orderType'
              and lngd_lang   = global_user_lang"
            lngd_key2 "input orderType" }
         if recno <> ? then
         display lngd_key2 @ orderType
         with frame a.
      end.
      else do:
         status input.
         readkey.
         apply lastkey.
      end.
   end.

   {us/wb/wbrp06.i &command = update
      &fields = "lot lot1 part part1 site site1
        line line1 endeff endeff1 altpart altpart1 report_bom orderType
        "
      &frm = "a"}

   if (c-application-mode <> 'web') or
      (c-application-mode = 'web' and
      (c-web-request begins 'data'))
   then do:

      bcdparm = "".
      {us/mf/mfquoter.i lot              }
      {us/mf/mfquoter.i lot1             }
      {us/mf/mfquoter.i part             }
      {us/mf/mfquoter.i part1            }
      {us/mf/mfquoter.i site             }
      {us/mf/mfquoter.i site1            }
      {us/mf/mfquoter.i line             }
      {us/mf/mfquoter.i line1            }
      {us/mf/mfquoter.i endeff           }
      {us/mf/mfquoter.i endeff1          }
      {us/mf/mfquoter.i altpart}
      {us/mf/mfquoter.i altpart1}
      {us/mf/mfquoter.i report_bom       }
      {us/mf/mfquoter.i orderType}

      if lot1 = "" then lot1 = hi_char.
      if part1 = "" then part1 = hi_char.
      if site1 = "" then site1 = hi_char.
      if line1 = "" then line1 = hi_char.
      if altpart1 = "" then altpart1  = hi_char.

   end.

   for first lngd_det where lngd_dataset     = c-lngd-dataset
      and lngd_field       = "orderType"
      and lngd_lang        = global_user_lang
      and lngd_key2        = orderType
   no-lock:
   end.
   if not available lngd_det
   then do:

      /* MUST BE (S)cheduled or (D)iscrete or (B)oth */
      {us/bbi/pxmsg.i &MSGNUM=10346 &ERRORLEVEL=4}

      if c-application-mode = "WEB"
         then
         return.

      else
      next-prompt
         orderType with frame a.
      undo,retry.
   end.
   order_type_key=lngd_key1.

   /* OUTPUT DESTINATION SELECTION */
   {us/gp/gpselout.i &printType = "printer"
      &printWidth = 132
      &pagedFlag = " "
      &stream = " "
      &appendToFile = " "
      &streamedOutputToTerminal = " "
      &withBatchOption = "yes"
      &displayStatementType = 1
      &withCancelMessage = "yes"
      &pageBottomMargin = 6
      &withEmail = "yes"
      &withWinprint = "yes"
      &defineVariables = "yes"}
   {us/bbi/mfphead.i}

   /*NOTE: LOOK AT ALL ORDERS CLOSED OR NOT*/
   mainloop:
   for each wo_mstr no-lock
         where wo_mstr.wo_domain = global_domain /* and (   wo_type = "c"*/
         and wo_lot >= lot and wo_lot <= lot1
         and wo_part >= part and wo_part <= part1
         and wo_site >= site and wo_site <= site1
         and wo_line >= line and wo_line <= line1
         and (wo_due_date >= endeff or endeff = ?)
         and (wo_due_date <= endeff1 or endeff1 = ?)

         and ((altpart = "" and altpart1 = hi_char)
         or can-find(first ptal_mstr where ptal_mstr.ptal_domain = global_domain
         and ptal_part             = wo_part
         and ptal_alt_part         >= altpart
         and ptal_alt_part         <= altpart1
         and ptal_active))
         and wo_type = "c"
         and ((wo_mfg_type = {&MFG_TYPE_DISCRETE} and
         (order_type_key = {&MFG_TYPE_DISCRETE}
         or order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE}))
         or (wo_mfg_type = {&MFG_TYPE_REPETITIVE} and
         (order_type_key = {&MFG_TYPE_REPETITIVE}
         or order_type_key = {&MFG_TYPE_DISCRETE_AND_REPETITIVE})))

         use-index wo_type_part,
         each pt_mstr no-lock
         where pt_mstr.pt_domain = global_domain and  pt_part = wo_part,
         each pl_mstr no-lock
         where pl_mstr.pl_domain = global_domain and  pl_prod_line =
         pt_prod_line
         by substring(wo_type,1,1) by wo_site by wo_part
         by wo_line by wo_due_date by wo_lot:

      {us/bbi/gprun.i ""rewodisp.p"" "(input wo_lot)"}

      for each wr_route no-lock
            where wr_route.wr_domain = global_domain and  wr_lot = wo_lot
         with frame frame1:


         /* RETRIEVE TEMP TABLE OF OPERATION COSTS */
         {us/px/pxrun.i &PROC       = 'getRoutingCosts'
            &PROGRAM    = 'wowrxr.p'
            &HANDLE     = ph_wowrxr
            &PARAM      = "(input wo_lot,
              input {&IRO_COST_SOURCE_WO_STD},
              output table tt_iro_det bind)"
            &NOAPPERROR = true
            }

         for first tt_iro_det
            where tt_iro_det.tt_iro_costSource = {&IRO_COST_SOURCE_WO_STD}
            and tt_iro_det.tt_iro_lot = wr_lot
            and tt_iro_det.tt_iro_op = wr_op
         no-lock:
         end.

         find wc_mstr  where wc_mstr.wc_domain = global_domain and
            wc_wkctr = wr_wkctr and wc_mch = wr_mch
         no-lock no-error.

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame frame1:handle).

         display
            skip(2)
            wr_op             colon 20
            wr_desc           at 31 no-label
            wr_setup          colon 76
            tt_iro_mtl_ll     colon 114 when (available tt_iro_det)
            wr_wkctr          colon 20
            wc_desc           at 31 no-label when (available wc_mstr)
            wr_setup_rte      colon 76
            tt_iro_mtl_tl     colon 114 when (available tt_iro_det)
            wr_mch            colon 20
            wr_run            colon 76
            tt_iro_lbr_ll     colon 114 when (available tt_iro_det)
            wr_milestone      colon 20
            wr_lbr_rate       colon 76
            tt_iro_lbr_tl     colon 114 when (available tt_iro_det)
            wr_mv_nxt_op      colon 20 label "Move Next Op"
            wr_bdn_pct        colon 76
            tt_iro_bdn_ll     colon 114 when (available tt_iro_det)
            wr_bdn_rate       colon 76
            tt_iro_bdn_tl     colon 114 when (available tt_iro_det)
            wr_mch_bdn        colon 76
            tt_iro_sub_ll     colon 114 when (available tt_iro_det)
            wr_mch_op         colon 76
            tt_iro_sub_tl     colon 114 when (available tt_iro_det)
            wr_sub_cost       colon 76
            tt_iro_cost_tot   colon 114 when (available tt_iro_det)
            wr_yield_pct      colon 76
         with frame frame1 side-labels width 132.

         if report_bom then do:

            for each wod_det no-lock
                  where wod_det.wod_domain = global_domain and  wod_lot =
                  wr_lot
                  and wod_op = wr_op,
                  each qad_wkfl no-lock
                  where qad_wkfl.qad_domain = global_domain and  qad_key1 =
                  "MFWORLA"
                  and qad_key2 = wod_lot + wod_part + string(wod_op)
                  and qad_charfld[1] = "s"

                  by wod_part with frame f-a:

               /* SET EXTERNAL LABELS */
               setFrameLabels(frame f-a:handle).

               ext_amt = wod_bom_qty * wod_bom_amt.

               find first ptal_mstr where ptal_mstr.ptal_domain = global_domain
                  and ptal_part             = wod_part
                  and ptal_active
               no-lock no-error.
               display
                  space(15)
                  wod_part
                  ptal_mstr.ptal_alt_part  when available(ptal_mstr)
                  wod_bom_qty
                  wod_bom_amt
                  ext_amt (total)
               with title (getFrameTitle("COMPONENT_MATERIALS",25))
                  width 110.

               {us/mf/mfrpchk.i &label=mainloop}

            end.

         end.

         {us/mf/mfrpchk.i &label=mainloop}

      end.

      page.

      {us/mf/mfrpchk.i}

   end.

   {us/mf/mfrtrail.i}

end.

{us/wb/wbrp04.i &frame-spec = a}

